<!--
 * @description: 功能
 * @author: Yoke
 * @Date: 2024-08-28 21:01:12
-->
<script setup lang="ts">
import type { UploadFileInfo, UploadOnChange } from 'naive-ui';
import { NUpload } from "naive-ui";
import { ref } from 'vue';

const emit = defineEmits(['update:value'])


const fileListRef = ref<UploadFileInfo[]>([])

const handleUploadChange: UploadOnChange = (info) => {
    const response = (info.event?.target as any)?.response
    if (response) {
        const res = JSON.parse(response)
        info.file.url = res.data.url
        info.file.data = res?.data
    }
    fileListRef.value = info.fileList;
    emit('update:value', info.fileList)
}

</script>

<template>
    <NUpload :file-list="fileListRef" accept="image/*" @change="handleUploadChange" list-type="image-card" :max="1" />
</template>